package com.wjx;

import com.wjx.jdkProxy.dynamic.JDKDynamicProxy;
import com.wjx.jdkProxy.dynamic.RealSubject;
import com.wjx.jdkProxy.dynamic.Subject;
import com.wjx.jdkProxy.staticState.HelloProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class Main {

    public static void main(String[] args) {

        // 保存生成的代理类的字节码文件
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
        // jdk动态代理测试 一
        System.out.println("---------我是jdk动态代理测试---------");
        Subject subject = new JDKDynamicProxy(new RealSubject()).getProxy();
        subject.doSomething();
        System.out.println("---------我是jdk动态代理测试---------");

        // 二
        RealSubject realSubject = new RealSubject();
        InvocationHandler handler = new JDKDynamicProxy(new RealSubject());
        Subject subjectTwo = (Subject) Proxy.newProxyInstance(handler.getClass().getClassLoader(),realSubject.getClass().getInterfaces(),handler);
        subjectTwo.doSomething();

        // jdk静态代理测试
        System.out.println("---------我是jdk静态代理---------");
        HelloProxy helloProxy = new HelloProxy();
        helloProxy.sayHello();
        System.out.println("---------我是jdk静态代理---------");
    }
}
